package parsing

import (
	"data-process/function"
	"strings"
)

// sex : true
// sex : false
// sex|auto : true
// sex|男-女 ：true
type BoolParse struct {
	field    string            // 属性
	key      string            // key
	value    bool              // 默认的value值
	size     int               // 需要生成的数据量
	function function.FuncBase // 函数
}

func NewBoolParsing(key string, value bool, size int) *BoolParse {
	if size == 0 {
		size = 10
	}
	return &BoolParse{
		key:   key,
		value: value,
		size:  size,
	}
}

func (b *BoolParse) parse() {
	if strings.Contains(b.key, "|") {
		keys := strings.Split(b.key, "|")
		b.field = keys[0]
		if keys[1] != "auto" {
			i := []rune(keys[1])
			b.function = function.MappingBool(string(i[0]), string(i[1]), b.size)
			return
		} else {
			b.function = function.AutoBool(true, b.size)
			return
		}
	} else {
		b.field = b.key
		b.function = function.DefaultBool(true, b.value, b.size)
	}

}

func (b *BoolParse) Build() (string, []interface{}, error) {
	b.parse()
	return b.field, b.function.Build(), nil
}
